﻿using System;
using UnityEngine;

namespace DL.UIBinding
{
    /// <summary>
    /// 实例化物品挂载
    /// </summary>
    public abstract class InfinityItem  : MonoBehaviour
    {
        private RectTransform m_SelfRT = null;
        public RectTransform SelfRT
        {
            get {
                if (m_SelfRT == null) {
                    m_SelfRT = GetComponent<RectTransform>();
                }
                return m_SelfRT;
            }
        }

        private void Awake()
        {
            OnInit();
        }

        protected InfinityContext context;

        public void Show(InfinityContext context)
        {
            this.context = context;
            OnShow();
            Refresh();
            HasData = this.context != null;
        }
        
        /// <summary>
        /// 用于绑定组件
        /// </summary>
        public abstract void OnInit();
        public abstract void OnShow();
        public abstract void Refresh(); //刷新调用
        public abstract void OnHide();
        
        public bool HasData;

        public void Hide()
        {
            OnHide();
            context = null;
            HasData = false;
        }
    }
}